// System Unit
// Processor Support

(*************)
(* Interface *)
(*************)
{$IFDEF Include_Modules_Header}

 Var
  // Default 8087 control word, FPU control register is set to this value.
  // CAUTION:  Setting this to an invalid value could cause unpredictable behavior.
  Default8087CW: Word = $1332;

 { FPU control word }

 Procedure Set8087CW(NewCW: Word);
 Function Get8087CW: Word;

{$ENDIF Include_Modules_Header}
(******************)
(* Implementation *)
(******************)
{$IFDEF Include_Modules_Implement}

 Procedure _INT_FPUInit;
  ASM
   FNINIT
   FWAIT
   FLDCW   Default8087CW
  END;

 Procedure Set8087CW(NewCW: Word);
  ASM
   MOV     Default8087CW, NewCW
   FNCLEX  // Don't raise pending exceptions enabled by the new flags
   FLDCW   Default8087CW
  END;

 Function Get8087CW: Word;
  ASM
   PUSH    0
   FNSTCW  [ESP].Word
   POP     EAX
  END;

{$ENDIF Include_Modules_Implement}
(******************)
(* Initialization *)
(******************)
{$IFDEF Include_Modules_Initialize}

 _INT_FPUInit;

{$ENDIF Include_Modules_Initialize}
(****************)
(* Finalization *)
(****************)
{$IFDEF Include_Modules_Finalize}
{$ENDIF Include_Modules_Finalize}
